/**
 * 
 */
package com.csair.youth.web.action;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.csair.youth.constant.Constant;
import com.csair.youth.database.Permission;

/**
 * @author mickey
 *
 */
public class HomeAction extends _BaseAction {
	private String url = "NoticeShow.action";
	
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String execute(){
		String redirectUrl = (String)this.getSessionAttribute(Constant.REDIRECT_URL_KEY);
		if(!StringUtils.isEmpty(redirectUrl)){
			url = redirectUrl;
			this.setSessionAttribute(Constant.REDIRECT_URL_KEY, null);
		}
		return SUCCESS;
	}
	
	public boolean isUrlInPermissions(String url, boolean hasContext){
		List permissions = (List)this.getSessionAttribute(Constant.USER_PERMISSION_MAP_KEY);
		if(permissions == null || permissions.size() == 0){
			return false;
		}
		else{
			int size = permissions.size();
			for(int i=0; i<size; i++){
				String ourl = ((Permission)permissions.get(i)).getUrl();
				if(hasContext){
					ourl = this.getServletRequest().getContextPath()+ourl;
				}
				if(StringUtils.equals(url, ourl) || StringUtils.equals(url+".action", ourl)){
					return true;
				}
			}
			return false;
		}
	}
}
